﻿<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:models="clr-namespace:MALRECrewrite.Models"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="MALRECrewrite.View.Sequels"
        Title="Sequels" Height="773" Width="749" d:DataContext="{d:DesignData /SampleData/SequelsViewModelSampleData8.xaml}" SnapsToDevicePixels="True">
    <Window.Resources>
    	<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <HierarchicalDataTemplate DataType="{x:Type models:Reference}" ItemsSource="{Binding Ref.References}" >
            <StackPanel>
                <TextBlock Text="{Binding Ref.Aid}"/>
                <CheckBox IsChecked="{Binding Ref.IsInAnimelist}"/>
                <TextBlock Text="{Binding Ref.Title}"/>
                <TextBlock Text="{Binding Ref.Uri}"/>
            </StackPanel>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="{x:Type models:SeasonAnime}" ItemsSource="{Binding References}" >
            <StackPanel>
                <TextBlock Text="{Binding Aid}"/>
                <CheckBox IsChecked="{Binding IsInAnimelist}"/>
                <TextBlock Text="{Binding Title}"/>
                <TextBlock Text="{Binding Uri}"/>
            </StackPanel>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate x:Key="SeasonAnimeTemplate" ItemsSource="{Binding References}">
        	<StackPanel>
        		<TextBlock Text="{Binding Title}"/>
        		<Border BorderBrush="Black" BorderThickness="1" Height="Auto" Visibility="{Binding IsInAnimelist, Converter={StaticResource BooleanToVisibilityConverter}}"/>
        	</StackPanel>
        </HierarchicalDataTemplate>
        <Style x:Key="TreeViewItemFocusVisual">
        	<Setter Property="Control.Template">
        		<Setter.Value>
        			<ControlTemplate>
        				<Rectangle/>
        			</ControlTemplate>
        		</Setter.Value>
        	</Setter>
        </Style>
        <PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
        <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
        	<Setter Property="Focusable" Value="False"/>
        	<Setter Property="Width" Value="16"/>
        	<Setter Property="Height" Value="16"/>
        	<Setter Property="Template">
        		<Setter.Value>
        			<ControlTemplate TargetType="{x:Type ToggleButton}">
        				<Border Background="Transparent" Height="16" Padding="5,5,5,5" Width="16">
        					<Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="Transparent" Stroke="#FF989898">
        						<Path.RenderTransform>
        							<RotateTransform Angle="135" CenterY="3" CenterX="3"/>
        						</Path.RenderTransform>
        					</Path>
        				</Border>
        				<ControlTemplate.Triggers>
        					<Trigger Property="IsMouseOver" Value="True">
        						<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF1BBBFA"/>
        						<Setter Property="Fill" TargetName="ExpandPath" Value="Transparent"/>
        					</Trigger>
        					<Trigger Property="IsChecked" Value="True">
        						<Setter Property="RenderTransform" TargetName="ExpandPath">
        							<Setter.Value>
        								<RotateTransform Angle="180" CenterY="3" CenterX="3"/>
        							</Setter.Value>
        						</Setter>
        						<Setter Property="Fill" TargetName="ExpandPath" Value="#FF595959"/>
        						<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF262626"/>
        					</Trigger>
        				</ControlTemplate.Triggers>
        			</ControlTemplate>
        		</Setter.Value>
        	</Setter>
        </Style>
        <Style x:Key="TreeViewItemStyle1" TargetType="{x:Type TreeViewItem}">
        	<Setter Property="Background" Value="Transparent"/>
        	<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        	<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        	<Setter Property="Padding" Value="1,0,0,0"/>
        	<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        	<Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
            <Setter Property="IsExpanded" Value="True"/>
        	<Setter Property="Template">
        		<Setter.Value>
        			<ControlTemplate TargetType="{x:Type TreeViewItem}">
        				<StackPanel Orientation="Horizontal" Margin="0" VerticalAlignment="Stretch">
        					<Grid Height="Auto">
        						<Grid.RowDefinitions>
        							<RowDefinition/>
        							<RowDefinition Height="*"/>
        						</Grid.RowDefinitions>
        						<Rectangle x:Name="TopOverlay" Fill="#FFADADED" Height="Auto" Margin="0" Stroke="{x:Null}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Visibility="Hidden"/>
								<Rectangle x:Name="BottomOverlay" Fill="#FFADADED" Height="Auto" Margin="0" Stroke="{x:Null}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Visibility="Hidden" Grid.Row="1"/>
        						<Grid Height="Auto" d:LayoutOverrides="Width, Height" Grid.RowSpan="2">
        							<Grid.ColumnDefinitions>
        								<ColumnDefinition Width="Auto"/>
        								<ColumnDefinition Width="*"/>
        								<ColumnDefinition Width="Auto"/>
        							</Grid.ColumnDefinitions>
        							<Path Data="M0,51.5L321.572613108564,51.5" Fill="#FFF4F4F5" Height="1" Stretch="Fill" Stroke="Black" Width="44.073" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Left"/>
        							<ToggleButton x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ExpandCollapseToggleStyle}" d:LayoutOverrides="Width, Height" Visibility="Hidden" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Bottom"/>
        							<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true" Height="Auto" Width="Auto" Margin="0,8" VerticalAlignment="Center" Padding="0" d:LayoutOverrides="Width" Grid.Column="1">
        								<ContentPresenter x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
        							</Border>
        							<Border x:Name="BorderBetween" Grid.Column="2" HorizontalAlignment="Stretch" Height="Auto" Margin="0,16,-1,16" VerticalAlignment="Stretch" Width="50" BorderThickness="0,0,1,0" BorderBrush="Black" Padding="0" >
        								<Path x:Name="RightLine" Data="M0,51.5L321.572613108564,51.5" Fill="#FFF4F4F5" Stretch="Fill" Stroke="Black" Margin="0,0,-1,0"/>
        							</Border>
        						</Grid>
        					</Grid>
        					<ItemsPresenter x:Name="ItemsHost" Height="Auto" Width="Auto" VerticalAlignment="Center"/>
        				</StackPanel>
        				<ControlTemplate.Triggers>
        					<Trigger Property="IsExpanded" Value="false">
        						<Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
        					</Trigger>
        					<Trigger Property="HasItems" Value="false">
        						<Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
								<Setter Property="Visibility" TargetName="RightLine" Value="Collapsed"/>
								<Setter Property="Visibility" TargetName="TopOverlay" Value="Hidden"/>
								<Setter Property="Visibility" TargetName="BottomOverlay" Value="Hidden"/>
								<Setter Property="Visibility" TargetName="BorderBetween" Value="Hidden"/>
        					</Trigger>
        					<Trigger Property="IsSelected" Value="true">
        						<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
        						<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
        					</Trigger>
        					<MultiTrigger>
        						<MultiTrigger.Conditions>
        							<Condition Property="IsSelected" Value="true"/>
        							<Condition Property="IsSelectionActive" Value="false"/>
        						</MultiTrigger.Conditions>
        						<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
        						<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        					</MultiTrigger>
        					<Trigger Property="IsEnabled" Value="false">
        						<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
        					</Trigger>
        				</ControlTemplate.Triggers>
        			</ControlTemplate>
        		</Setter.Value>
        	</Setter>
        	<Style.Triggers>
        		<Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
        			<Setter Property="ItemsPanel">
        				<Setter.Value>
        					<ItemsPanelTemplate>
        						<VirtualizingStackPanel/>
        					</ItemsPanelTemplate>
        				</Setter.Value>
        			</Setter>
        		</Trigger>
        	</Style.Triggers>
        </Style>
        <ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
        	<StackPanel IsItemsHost="True" VerticalAlignment="Center"/>
        </ItemsPanelTemplate>
    </Window.Resources>
    <Grid>
        <TreeView ItemTemplate="{DynamicResource SeasonAnimeTemplate}" ItemsSource="{Binding RootReferences}" Margin="0" ItemContainerStyle="{DynamicResource TreeViewItemStyle1}" ItemsPanel="{DynamicResource ItemsPanelTemplate1}" />
    </Grid>
</Window>